package com.mapforge.gui;

import java.awt.Point;
import java.awt.Rectangle;

import com.mapforge.gui.interfaces.TileMapEditorGUIInterface;
import com.mapforge.gui.tools.SelectedTiles;
import com.mapforge.map.tools.TileClipboard;

public class CutCopyPasteListener extends AbstractCutCopyPasteListener {
	private Point point;

	public CutCopyPasteListener(TileMapEditorGUIInterface mapEditorGUI) {
		super(mapEditorGUI);
	}

	public void cutTiles() {
		TileClipboard clipboard = TileClipboard.getHandle();
		SelectedTiles selection = SelectedTiles.getHandle();
		// copy previous selection
		clipboard.cutToClipboard(selection, getLayer());
		// TODO fire edit performed to interested listeners
	}

	public void copyTiles() {
		TileClipboard clipboard = TileClipboard.getHandle();
		SelectedTiles selection = SelectedTiles.getHandle();
		clipboard.copyToClipboard(selection, getLayer());
	}

	public void pasteTiles() {
		TileClipboard clipboard = TileClipboard.getHandle();
		SelectedTiles.getHandle().clearSelection();
		Rectangle rect = getTileMapEditorGUI().getVisibleTileRectangle();
		Point point = new Point(rect.x, rect.y);
		clipboard.writeClipboardSelection(point, getLayer());
	}

	@Override
	public void pasteTilesAtLocation() {
		TileClipboard clipboard = TileClipboard.getHandle();
		SelectedTiles.getHandle().clearSelection();
		clipboard.writeClipboardSelection(point, getLayer());
	}

	@Override
	public void setPoint(Point point) {
		this.point = point;
	}
}